const axios = require('axios');
const config = require('../configs/config');

const token = config.token;

const getCourses = async () => {
    const { data } = await axios.get(`https://api.duanshu.com/h5/content/user/column?page=1&count=10&order_by=-update_time&shop_id=e5gd329004e798b71j`, {
        headers: {
            'X-Member': token
        }
    });
    return data;
}

const getChaptersByCourseId = async (id) => {
    const { data } = await axios.get(`https://api.duanshu.com/fairy/api/v1/courses/${id}/chapters/?id=${id}&size=999&shop_id=e5gd329004e798b71j`, {
        headers: {
            'X-Member': token
        }
    });
    return data;
}

const getChapter = async (id) => {
    const { data } = await axios.get(`http://api.duanshu.com/fairy/api/v2/examinations/${id}/?shop_id=e5gd329004e798b71j`, {
        headers: {
            'X-Member': token
        }
    });
    return data;
}

const getQuestions = async (id) => {
    const { data } = await axios.get(`http://api.duanshu.com/fairy/api/v2/examinations/${id}/answer_card/?shop_id=e5gd329004e798b71j`, {
        headers: {
            'X-Member': token
        }
    });
    return data;
}

const getQuestionDetial = async (id) => {
    const { data } = await axios.get(`http://api.duanshu.com/fairy/api/v2/examinations/materials/${id}/?shop_id=e5gd329004e798b71j`, {
        headers: {
            'X-Member': token
        }
    });
    return data;
}

module.exports = {
    getCourses,
    getChaptersByCourseId,
    getChapter,
    getQuestions,
    getQuestionDetial
}